unit UNIDACUtils;

interface

uses
  siAuto,
  SysUtils, DB, MemDS, DBAccess, Uni;

procedure ClearQuery(Query:TUniQuery);
function OpenQuery(Query:TUniQuery; var ErrorMsg:String):Boolean;
function ExecuteQuery(Query:TUniQuery; var ErrorMsg:String):Boolean;

implementation

procedure ClearQuery(Query:TUniQuery);
begin
  if Query.Active then Query.Close;
  Query.SQL.Clear;
end;

function OpenQuery(Query:TUniQuery; var ErrorMsg:String):Boolean;
begin
  Result := False;
  try
    Query.Open;
    Result := True;
  Except on e:Exception do
    begin
      ErrorMsg := e.Message;
      siMain.LogException(e, 'UNIDACUtils.Open');
      siMain.LogSql(e.Message, Query.SQL.Text);
    end;
  end;
end;

function ExecuteQuery(Query:TUniQuery; var ErrorMsg:String):Boolean;
begin
  Result := False;
  try
    Query.Execute;
    Result := True;
  Except on e:Exception do
    begin
      ErrorMsg := e.Message;
      siMain.LogException(e, 'UNIDACUtils.Execute');
      siMain.LogSql(e.Message, Query.SQL.Text);
    end;
  end;
end;

end.
